home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Magazine / Online / httpproxy / goodies / proxyindex.rexx < prev   
OS/2 REXX Batch file  |  1996-08-20  |  13KB  |  380 lines

  1. /* proxyindex.rexx (0.63) 01-Aug-96
  2.    by mago@is-bremen.de
  3.    Written for httpproxy 0.14 alpha (30-Jul-96)
  4.  - Requirements: rexxtricks.library (Aminet), list, sort, type, echo, search
  5.  - Using this script without an argument, it creates three index files,
  6.    html sorted alpha. by time of file creation and an image page.
  7.    Plus an AmigaGuide file, wich enables you to delete single Proxy-files
  8.    by clicking on them (without warning). No Directorys are deleted.
  9.  - The file rexx:proxydel.rexx will be written. It's used by the guide-file.
  10.  - In an optional argument you can specify a searchpattern.  All lines in
  11.    in the html and the images page containing this string are written into
  12.    {stem}g.html
  13.  - This script works only on the /http/ dir, so far.
  14. */
  15.  
  16. /********* config *********/
  17.  
  18. centdok  = 0              /* center links or align left (bool) */
  19. striport = 1              /* strip port numbers from URL's (bool) */
  20. port     = 80             /* port on wich your proxy is running */
  21. fontsize = 3              /* Between 1 and 6 */
  22. cachedir = 'data:cache/'  /* With trailing slash! */
  23. stem     = 'data:cache'   /* stem of the resulting files.
  24.                  As there are:
  25.                  {stem}.html   the main page, only html
  26.                  {stem}i.html  the image page
  27.                  {stem}ts.html all html pages sorted by time
  28.                  {stem}g.html  extract from both html pages
  29.                  {stem}.guide  to delete single cache entries */
  30. /* If your LOCALE language is not German you may have to change this var */
  31.      monthident = 'Jan Feb Mär Apr Mai Jun Jul Aug Sep Okt Nov Dez'
  32.  
  33. /**************************/
  34.  
  35. address command;parse arg pat;numfiles=0;status=1
  36. /*'copy amitcp:bin/httpfetch ram:'*/
  37. 'Resident >nil: c:list'
  38. if fontsize > 1 then do;bs=fontsize;hs=bs-1;end
  39. else do;bs=fontsize;hs=bs;end
  40. if length(pat) > 0 then call grep
  41. 'echo >'stem'cache.cont'
  42.  
  43. if ~show('L','rexxtricks.library') then call addlib('rexxtricks.library',0,-30,0)
  44. tcnt=0;cnt=0;icnt=0
  45. fn.0 = 14
  46. fn.1 = '/* 'stem'.guide */;address command;parse arg string'
  47. fn.2 = 'if index(string,"@@") == 0 then "delete >nil: "string'
  48. fn.3 = 'else'
  49. fn.4 = 'do'
  50. fn.5 = '   off=index(string,@@)'
  51. fn.6 = '   roff=off'
  52. fn.7 = '   do while off > 0'
  53. fn.8 = '      roff=off'
  54. fn.9 = '      off=index(string,@@,off+1)'
  55. fn.10= '   end'
  56. fn.11= '   str=string'
  57. fn.12= '   str=delstr(insert("!",str,roff+1),roff,1)'
  58. fn.13= '   "delete >nil: "string" "str'
  59. fn.14= 'end'
  60. if ~writefile('rexx:proxydel.rexx',fn) then call ferr('rexx:proxydel.rexx')
  61. if ~open(tmp,'t:pi.tmp',w) then call ferr('t:pi.tmp')
  62. if ~open(tmpt,'t:timeindex.tmp',w) then call ferr('t:timeindex.tmp')
  63. if ~open(tmpx,'t:logx.tmp',w) then call ferr('t:logx.tmp')
  64. if ~open(tmpg,'t:logg.tmp',w) then call ferr('t:logg.tmp')
  65. if ~open(guide,stem'.guide',w) then call ferr(stem'.guide')
  66. call writeln(guide,'@database "Httpproxy.guide"')
  67. call writeln(guide,'@node main "Delete HttpProxy (0.14) Cache"')
  68. call close(guide)
  69. call htmlhead
  70.  
  71. call getcont /* Explore the cachedir */
  72.  
  73. call writech(stdout,' 'numfiles' ')
  74. do i=1 to numfiles-1  /* Seperate files into page and image */
  75.    if index(upper(ofn.i),'.MOV') == 0 & index(upper(ofn.i),'.MPG') == 0 & index(upper(ofn.i),'NPH-COUNT') == 0 & index(upper(ofn.i),'.JPEG') == 0 & index(upper(ofn.i),'.GIF') == 0 & index(upper(ofn.i),'.JPG') == 0 then
  76.    do
  77.       call writeln tmp,'<a href="'ofn.i'">'str(ofn.i)'</a>'stat()'<br>'
  78.       call writeln tmpt,time.i' <a href="'ofn.i'">'str(ofn.i)'</a>'stat()'<br>'
  79.       trace off
  80.       cnt=cnt+1
  81.    end
  82.    else
  83.    do
  84.       call writeln tmpx,'<a href="'ofn.i'">'str(ofn.i)'</a>'stat()'<br>'
  85.  trace off
  86.       icnt=icnt+1
  87.    end
  88.    tcnt=tcnt+1
  89.    if tcnt == 101 then
  90.    do
  91.       tcnt=0
  92.       call writech(stdout,'*')
  93.    end
  94.    call writeln(tmpg,' @{ub}@{"'str(ofn.i)'" RX "rexx:proxydel.rexx 'ofp.i'"}@{ub}'stat())
  95. trace off
  96. end
  97. call close(tmp);call close(tmpx);call close tmpg;call close tmpt;say
  98.  
  99. /* creation of the final files */
  100.  
  101. 'Sort t:timeindex.tmp t:time.tmp'
  102. call tsortpage
  103. 'Sort t:logg.tmp t:loge.tmp'
  104. 'Type >>'stem'.guide t:loge.tmp'
  105. 'Echo >>'stem'.guide @endnode'
  106. 'Sort t:pi.tmp t:log2.tmp';'Sort t:logx.tmp t:logy.tmp'
  107. 'Type >>'stem'.html t:log2.tmp'
  108. if ~open(html,stem'.html',a) then call ferr(stem'.html')
  109. call writeln(html,cenl(0)'<h/'bs'><pre>')
  110. call writeln(html,' Number of Pages: 'cnt'</pre>')
  111. call writeln(html,'<ul><a name="bot"></a>')
  112. call writeln(html,'<h'hs'><a href="#htm">html</a>')
  113. call writeln(html,'<a href="file:///'stem'i.html">ima<>ges</a>')
  114. call writeln(html,'<a href="file:///'stem'ts.html">tim<>esort</a>')
  115. call writeln(html,'<a href="file:///'stem'g.html" >cac<>heg<>rep</h'hs'></a></ul></body>')
  116. call close(html)
  117. call gfxhead
  118. 'Type >>'stem'i.html t:logy.tmp'
  119. call open(html,stem'i.html',a)
  120. call writeln(html,cenl(0)'<h/'bs'><pre>')
  121. call writeln(html,' Number of images: 'icnt'</pre>')
  122. call writeln(html,'<ul><a name=bot></a></body>')
  123. call writeln(html,'<a href="file:///'stem'.html"><h'hs'>html</a>')
  124. call writeln(html,'<a href="#gfx">ima<>ges</a>')
  125. call writeln(html,'<a href="file:///'stem'ts.html">tim<>esort</a>')
  126. call writeln(html,'<a href="file:///'stem'g.html" >cac<>heg<>rep</h'hs'></a></ul>')
  127. call close(html)
  128. 'Delete >nil: t:#?.tmp'
  129. exit
  130.  
  131. stat:
  132. if status then
  133. do
  134.    if ofs.i == 'empty' then return ' 0 '
  135. /*   else  This is dangerous to use! it discarded my cache!
  136.    do
  137.       'ram:httpfetch >t:cont.tmp 'ofn.i' from localhost:80 '
  138.       if rc ~= 10 then
  139.       do
  140.      if ~open(ctst,'t:cont.tmp',r) then call ferr('t:ocnt.tmp')
  141.      ad=readch(ctst,100)
  142.      call close(ctst)
  143.      if index(upper(ad),error) > 0 then return ' E '
  144.      else return ''
  145.       end
  146.       else return ' U '
  147.    end */
  148. end
  149. else return ''
  150.  
  151. cenl:
  152. parse arg switch
  153. if centdok then
  154. do
  155.    if switch then return '<center>'
  156.    else return '</center>'
  157. end
  158. else return ''
  159.  
  160. tmod: /* DD-MMM-JJ HH:MM:SS -> JJMMDD HH to make it sortable and short */
  161. return delstr(fd.i,1,7)||month(substr(fd.i,4,3))||substr(fd.i,1,2)' 'delstr(ft.i,3)
  162.  
  163. month:  /* convert the month abbrev. into number */
  164. parse arg mt
  165. select
  166.    when mt == word(monthident,1) then x='01'
  167.    when mt == word(monthident,2) then x='02'
  168.    when mt == word(monthident,3) then x='03'
  169.    when mt == word(monthident,4) then x='04'
  170.    when mt == word(monthident,5) then x='05'
  171.    when mt == word(monthident,6) then x='06'
  172.    when mt == word(monthident,7) then x='07'
  173.    when mt == word(monthident,8) then x='08'
  174.    when mt == word(monthident,9) then x='09'
  175.    when mt == word(monthident,10) then x='10'
  176.    when mt == word(monthident,11) then x='11'
  177.    when mt == word(monthident,12) then x='12'
  178.    otherwise nop
  179. end
  180. return x
  181.  
  182. str: procedure
  183. parse arg t
  184. if index(t,'http://') > 0 then t=delstr(t,1,7)
  185. return t
  186.  
  187. grep:
  188. if ~exists(stem'.html') then call ferr(stem'.html')
  189. if ~exists(stem'i.html') then call ferr(stem'i.html')
  190. if ~open(html,stem'g.html',w) then call ferr(stem'g.html')
  191. call writeln(html,'<html><head><title>httpproxy index 'time(n)' 'date(e)'</TITLE></HEAD><BODY>')
  192. call writeln(html,'<ul><a href=file:///'stem'.html><h'hs'>html</a>')
  193. call writeln(html,'<a href="file:///'stem'ts.html">timeso<>rt</a>')
  194. call writeln(html,'<a href=file:///'stem'i.html>images</h'hs'></a></ul><h'bs'>'cenl(1))
  195. call close(html)
  196. 'Search >>'stem'g.html 'stem'.html 'pat' 'nonum
  197. 'Search >>'stem'g.html 'stem'i.html 'pat' 'nonum
  198. 'Echo >>'stem'g.html "'cenl(0)'<h/'bs'></body>"'
  199. exit
  200.  
  201. ferr:
  202. parse arg fname
  203. say "Can't open: "fname
  204. exit
  205.  
  206. htmlhead: /* html page */
  207. if ~open(html,stem'.html',w) then call ferr(stem'.html')
  208. call writeln(html,'<HTML><HEAD><TITLE>httpproxy in<>dex - html 'time(n)' 'date(e)'</TITLE></HEAD><BODY>')
  209. call writeln(html,'<ul><a name='d2c(34)'htm'd2c(34)'><h'hs'>html</a>')
  210. call writeln(html,'<a href="file:///'stem'i.html">ima<>ges</a>')
  211. call writeln(html,'<a href="file:///'stem'ts.html">ti<>meso<>rt</a>')
  212. call writeln(html,'<a href="file:///'stem'g.html" >ca<>cheg<>rep</a>')
  213. call writeln(html,'<a href="#bot">bottom</a></h'hs'></ul><h'bs'>'cenl(1))
  214. call close(html)
  215. return
  216.  
  217. gfxhead: /* images page */
  218. if ~open(html,stem'i.html',w) then call ferr(stem'.html')
  219. call writeln(html,'<HTML><HEAD><TITLE>httpproxy index - ima<>ges 'time(n)' 'date(e)'</TITLE></HEAD><BODY>')
  220. call writeln(html,'<ul><a name='d2c(34)'gfx'd2c(34)'><h'hs'>ima<>ges</a>')
  221. call writeln(html,'<a href="file:///'stem'.html">html</a>')
  222. call writeln(html,'<a href="file:///'stem'ts.html">ti<>meso<>rt</a>')
  223. call writeln(html,'<a href="file:///'stem'g.html" >ca<>chegr<>ep</a>')
  224. call writeln(html,'<a href="#bot">bot<>tom</a></h'hs'></ul><h'bs'>'cenl(1))
  225. call close(html)
  226. return
  227.  
  228. tsortpage: /* time-sorted page */
  229. if ~open(html,stem'ts.html',w) then call ferr(stem'ts.html')
  230. call writeln(html,'<HTML><HEAD><TITLE>httpproxy index - html timesort 'time(n)' 'date(e)'</TITLE></HEAD><BODY>')
  231. call writeln(html,'<ul><a name='d2c(34)'top'd2c(34)'><h'hs'>tim<>es<>ort</a>')
  232. call writeln(html,'<a href="file:///'stem'.html">html</a>')
  233. call writeln(html,'<a href="file:///'stem'i.html">ima<>ges</a>')
  234. call writeln(html,'<a href="#bot">bottom</a>')
  235. call writeln(html,'<a href="file:///'stem'g.html">cac<>hegr<>ep</h'hs'></a></ul><h'bs'>'cenl(1))
  236. tscnt=0
  237. if ~readfile('t:time.tmp',fnt) then call ferr('t:time.tmp')
  238. tsc=fnt.0                         /* reverse the timesort tmp to get the */
  239. do i=1 to fnt.0                   /* last request on top                 */
  240.    call writeln(html,fnt.tsc)
  241.    tsc=tsc-1
  242. end
  243. call writeln(html,cenl(0)'<ul><a name="bot"></a>')
  244. call writeln(html,'<h'hs'><a href="#top">top</a>')
  245. call writeln(html,'<a href="file:///'stem'.html">html</a>')
  246. call writeln(html,'<a href="file:///'stem'i.html">images</a>')
  247. call writeln(html,'<a href="file:///'stem'ts.html">timesort</a>')
  248. call writeln(html,'<a href="file:///'stem'g.html" >cachegrep</h'hs'></a></ul></body>')
  249. call close(html)
  250. return
  251.  
  252. getcont: /* Parse chachedir tree */
  253. debug=0;cnt=1;stage=0
  254. path=cachedir'http'
  255. call open(log,'ram:log',w)
  256. 'List >t:cdir.tmp lformat "%p%n %d %t %b" dates 'path
  257. if ~readlines('t:cdir.tmp',,,'%s %s %s %s','fn fd ft fs') then call ferr('t:cdir.tmp')
  258. do forever
  259.    stage=stage+1
  260.    if debug then
  261.    do
  262.       say;say 'Processing Stage: 'stage;say
  263.       say copies(#,50)
  264.       say copies(#,16)' ident files 'copies(#,21)
  265.       say copies(#,50)
  266.       say;say 'Number of items: 'fn.0
  267.    end
  268.    else call writech(stdout,'/')
  269.    nextdir=0
  270.    do i=1 to fn.0
  271.       /* Processing of hash Files */
  272.       if index(fn.i,'@dirurl') > 0 | index(filepart(fn.i),'@@') > 0 | index(filepart(fn.i),'@!') > 0 then
  273.       do
  274.      if index(fn.i,'@dirurl') > 0 then
  275.      do
  276.         call open(fhandle,fn.i,r)
  277.         htpath=readln(fhandle)
  278.         call close(fhandle)
  279.      end
  280.      else
  281.      do
  282.         if index(filepart(fn.i),'@!') > 0 then
  283.         do
  284.            if fs.i == 'Dir' then /* if directory, queue to list */
  285.            do
  286.           nextdir=nextdir+1
  287.           q.nextdir=fn.i
  288.            end
  289.            else
  290.            do
  291.           if ~open(fh,pathpart(fn.i)'/'insert(@,delstr(filepart(fn.i),2,1),1),r) then call ferr(pathpart(fn.i)'/'insert(@,delstr(filepart(fn.i),2,1),1))
  292.           numfiles=numfiles+1
  293.           ofp.numfiles=pathpart(fn.i)'/'insert(@,delstr(filepart(fn.i),2,1),1)
  294.           time.numfiles=tmod()
  295.           ofn.numfiles=xport(readln(fh)||' 'striport);call close fh
  296.           ofs.numfiles=fs.i
  297.           if debug then do;say pathpart(fn.i)'/'insert(@,delstr(filepart(fn.i),2,1),1)' 'fs.i;end
  298.            end
  299.         end
  300.      end
  301.       end
  302.       else
  303.       do
  304.      if fs.i == 'Dir' then /* if directory, queue to list */
  305.      do
  306.         nextdir=nextdir+1
  307.         q.nextdir=fn.i
  308.      end
  309.      else
  310.      do
  311.         call addout
  312.         ofn.numfiles=ctourl(fn.i' 'striport' 'htpath)
  313.         if debug then do;say left(fn.i,65)' 'fs.i;say 'htPath: 'htpath;end
  314.      end
  315.       end
  316.    end
  317.    if nextdir == 0 then break
  318.    if debug then
  319.    do
  320.       say;say 'dirs to list';say
  321.       do k=1 to nextdir
  322.      say q.k
  323.       end
  324.       say;say copies(#,16)' list 'copies(#,26);say
  325.    end
  326.    flcnt=0
  327.    do i=1 to nextdir
  328.       'List >t:cdir.tmp lformat "%p%n %d %t %b" dates "'q.i'/#?"'
  329.       if ~readlines('t:cdir.tmp',,,'%s %s %s %s','tfn tfd tft tfs') then call ferr('t:cdir.tmp')
  330.       dul=lsearch('*@dirurl',tfn,,,p) /* @dirurl to start of list */
  331.       if dul > 1 then
  332.       do
  333.      tmp.1 = tfn.dul ; tfn.dul = tfn.1 ; tfn.1 = tmp.1
  334.      tmp.2 = tfd.dul ; tfd.dul = tfd.1 ; tfd.1 = tmp.2
  335.      tmp.3 = tft.dul ; tft.dul = tft.1 ; tft.1 = tmp.3
  336.      tmp.4 = tfs.dul ; tfs.dul = tfs.1 ; tfs.1 = tmp.4
  337.       end
  338.       if tfn.0 > 0 then
  339.       do
  340.      acnt=1
  341.      if debug then do;say;say 'Dir contents of: 'q.i;say;end
  342.      do j=flcnt to flcnt+tfn.0-1
  343.         flcnt=flcnt+1
  344.         fn.flcnt = tfn.acnt /* filename */
  345.         fd.flcnt = tfd.acnt /* filedate */
  346.         ft.flcnt = tft.acnt /* filetime */
  347.         fs.flcnt = tfs.acnt /* filezize */
  348.         if debug then say 'Fnr: 'flcnt' 'fn.flcnt' 'fs.flcnt
  349.         acnt=acnt+1
  350.      end
  351.       end
  352.    end
  353.    fn.0=flcnt
  354.    if debug then say
  355. end
  356. return
  357.  
  358. addout: /* Add an item to the output-list */
  359. numfiles=numfiles+1
  360. ofp.numfiles=fn.i
  361. time.numfiles=tmod()
  362. ofs.numfiles=fs.i
  363. return
  364.  
  365. ctourl: procedure expose port /* Convert the filepath into URL */
  366. parse arg t' 's' 'p
  367. t=p||filepart(t)
  368. if substr(t,length(t)) == @ then t=substr(t,1,length(t)-1)
  369. if port == substr(t, index(t,':',8)+1, index(t,'/',8)-index(t,':',8)-1) then
  370. if s then t=delstr(t, index(t,':',8),index(t,'/',8)-index(t,':',8)) /* strip port nr */
  371. return t
  372.  
  373. xport: procedure expose port
  374. parse arg t' 's
  375. if port == substr(t, index(t,':',8)+1, index(t,'/',8)-index(t,':',8)-1) then
  376. if s then t=delstr(t, index(t,':',8), index(t,'/',8)-index(t,':',8)) /* strip port nr */
  377. return t
  378.  
  379. /* eof */
  380.